# coding = utrf-8

from PySide6.QtWidgets import QWidget,QLineEdit,QPushButton,QHBoxLayout,QApplication
from PySide6.QtCore import QDateTime
import sys

class MyWidget(QWidget):
    """自定义窗口控件

    :param QWidget: 基础控件
    """
    def __init__(self):
        """构造函数
        """
        super().__init__()
    
    def setupUi(self):
        """设置用户界面
        """
        # 主布局使用水平布局
        hbox = QHBoxLayout(self)

        #创建 行编辑和添加按钮
        self.lineEdit = QLineEdit()
        self.insertDateBtn = QPushButton("插入当前日期")

        # 添加控件到布局
        hbox.addWidget(self.lineEdit)
        hbox.addWidget(self.insertDateBtn)
    
    def setEventBind(self):
        """设置事件绑定
        """
        self.insertDateBtn.clicked.connect(self.insertDate)

    def insertDate(self):
        """插入日期
        """
        currentDateTime = QDateTime.currentDateTime()
        formattedTime = currentDateTime.toString("hh:mm yyyy/MM/dd")
        self.lineEdit.insert(formattedTime)

if __name__ == "__main__":
    app = QApplication(sys.argv)
    myWidget = MyWidget()
    myWidget.show()
    myWidget.setupUi()
    myWidget.setEventBind()
    sys.exit(app.exec())